import axios from 'axios'
import { BASE_URL } from './url'
import { Toast } from 'antd-mobile'
const instance = axios.create({
  baseURL: BASE_URL,
  // timeout: 5000,
})

// 请求拦截器
instance.interceptors.request.use(
  function (config) {
    Toast.show({
      icon: 'loading',
      content: '加载中…',
    })
    return config
  },
  function (error) {
    return Promise.reject(error)
  }
)

// 响应拦截器
instance.interceptors.response.use(
  function (response) {
    Toast.clear()
    return response.data
  },
  function (error) {
    Toast.clear()
    return Promise.reject(error)
  }
)

export default instance
